import 'package:OASys/entity/UserAdd.dart';
import 'package:OASys/entity/UserVo.dart';
import 'package:OASys/httpConfig/DioManager.dart';
import 'package:OASys/httpConfig/ErrorEntity.dart';
import 'package:OASys/httpConfig/NWApi.dart';
import 'package:OASys/httpConfig/NWMethod.dart';

class UserApi {
  void info({Function(UserVo) success, Function(ErrorEntity) error}) {
    DioManager().request<UserVo>(
      NWMethod.GET,
      NWApi.getInfo,
      success: success,
      error: error,
    );
  }

  void register(String username, String password,
      {Function(String) success, Function(ErrorEntity) error}) {
    DioManager().request<String>(
      NWMethod.POST,
      NWApi.register,
      params: {
        "username": username,
        "password": password,
      },
      success: success,
      error: error,
    );
  }

  void list(int page, int limit,
      {UserVo andQuery,
      Function(List<UserVo>) success,
      Function(ErrorEntity) error}) {
    DioManager().requestList<UserVo>(
      NWMethod.POST,
      "/front/user/list",
      params: {
        "page": page,
        "limit": limit,
        "andQuery": andQuery,
      },
      success: success,
      error: error,
    );
  }

  void save(UserAdd info,
      {Function(String) success, Function(ErrorEntity) error}) {
    DioManager().request<String>(
      NWMethod.PUT,
      "/front/user/save",
      params: info.toJson(),
      success: success,
      error: error,
    );
  }

  void remove(int id, {Function(String) success, Function(ErrorEntity) error}) {
    DioManager().request<String>(
      NWMethod.DELETE,
      "/front/user/remove/$id",
      success: success,
      error: error,
    );
  }

  void setStatus(int id, int status,
      {Function(String) success, Function(ErrorEntity) error}) {
    DioManager().request<String>(
      NWMethod.GET,
      "/front/user/setStatus/$id/$status",
      success: success,
      error: error,
    );
  }
}
